package com.xidian.zhiancloud.service.luling.RiskIdentificationPart;

import com.xidian.zhiancloud.dao.RiskAssessmentStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.RiskAssessmentStatus;
import com.xidian.zhiancloud.model.RiskAssessmentStatusExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RiskAssessmentStatusService {
    @Autowired
    private RiskAssessmentStatusMapper  riskAssessmentStatusMapper;
    public void insertByIds(Long[] ids) {
        for (Long id : ids) {
            int result = riskAssessmentStatusMapper.deleteByPrimaryKey(id);
            if (result == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }

    }

    public List<RiskAssessmentStatus>getById(String type) {
        RiskAssessmentStatusExample riskAssessmentStatusExample = new RiskAssessmentStatusExample();
        RiskAssessmentStatusExample.Criteria criteria = riskAssessmentStatusExample.createCriteria();
        criteria.andTypeEqualTo(type);
        List<RiskAssessmentStatus> riskAssessmentStatusList = riskAssessmentStatusMapper.selectByExample(riskAssessmentStatusExample);
        if (riskAssessmentStatusList == null) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        return riskAssessmentStatusList;
}

    public  Object getList(String riskName, Date deadlineIden, String type, String key, int current, int size) {
        RiskAssessmentStatusExample riskAssessmentStatusExample = new RiskAssessmentStatusExample();
        RiskAssessmentStatusExample.Criteria criteria1 = riskAssessmentStatusExample.createCriteria();
        RiskAssessmentStatusExample.Criteria criteria2 = riskAssessmentStatusExample.createCriteria();
        RiskAssessmentStatusExample.Criteria criteria3 = riskAssessmentStatusExample.createCriteria();
        if (riskName != null){
            criteria1.andRiskNameEqualTo(riskName);
            criteria2.andRiskNameEqualTo(riskName);
            criteria3.andRiskNameEqualTo(riskName);
        }
        if (type != null) {
            criteria1.andTypeEqualTo(type);
            criteria2.andTypeEqualTo(type);
            criteria3.andTypeEqualTo(type);
        }
        if (deadlineIden != null) {
            criteria1.andDeadlineIdenEqualTo(String.valueOf(deadlineIden));
            criteria2.andDeadlineIdenEqualTo(String.valueOf(deadlineIden));
            criteria3.andDeadlineIdenEqualTo(String.valueOf(deadlineIden));
        }
        if (key != null && !"".equals(key)) {
            criteria1.andDeadlineIdenEqualTo('%' + key + '%');
            criteria2.andTypeEqualTo('%' + key + '%');
            criteria3.andRiskNameEqualTo('%' + key + '%');
            riskAssessmentStatusExample.or(criteria2);
            riskAssessmentStatusExample.or(criteria3);
        }
        Integer a = 4;
        Integer b = 7;
        criteria1.andStateEqualTo(a.toString());
        criteria2.andStateEqualTo(b.toString());
        riskAssessmentStatusExample.or(criteria2);
        return riskAssessmentStatusMapper.selectByExampleWithRowbounds(riskAssessmentStatusExample, new RowBounds(current, size));
    }
    }

